# date:20210219
from typing import List
import collections

class Solution:
    def findShortestSubArray(self, nums: List[int]) -> int:
        list1 = [(k, v) for k, v in collections.Counter(nums).items()]
        list1 = sorted(list1, key=lambda x: x[1], reverse=True)
        result = []
        for tuple1 in list1:
            if tuple1[1] != list1[0][1]:
                break
            min1 = nums.index(tuple1[0])
            max1 = len(nums) - nums[::-1].index(tuple1[0]) - 1
            result.append(max1 - min1 + 1)
        return min(result)




model = Solution()

nums = [1, 2, 2, 3, 1]
print(model.findShortestSubArray(nums))

nums = [1,2,2,3,1,4,2]
print(model.findShortestSubArray(nums))